//
//  UIButton+Extension.swift
//  weibo
//
//  Created by zcp on 16/5/17.
//  Copyright © 2016年 zcp. All rights reserved.
//

import UIKit

///UIButton扩展
extension UIButton {


    //扩展中创建对象只能通过便利函数来创建
    convenience init(bgImageName: String,imageName: String,title: String,titleColor: UIColor = UIColor.lightGrayColor(),fontSize: CGFloat = 12){
        //便利函数内部一定要调用本类的构造函数来真正创建对象
        self.init(type: UIButtonType.Custom)
        //设置
        self.setBackgroundImage(UIImage(named: bgImageName+"_highlighted"), forState: UIControlState.Highlighted)
        self.setBackgroundImage(UIImage(named: bgImageName), forState: UIControlState.Normal)
        self.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        self.setTitle(title, forState: UIControlState.Normal)
        self.setTitleColor(titleColor, forState: UIControlState.Normal)
        self.titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        
    
    }
    
}
